package com.yili.oa.service.impl;

import com.yili.oa.dao.PaymentDescMapper;
import com.yili.oa.entity.SearchBase;
import com.yili.oa.models.PaymentDesc;
import com.yili.oa.models.PaymentDescExample;
import com.yili.oa.service.PaymentDescService;
import com.yili.oa.utils.Exception.AjaxException;
import com.yili.oa.utils.annotate.DataBase;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lxr
 * @version v0.01
 * @date 2019/7/22 0022
 * @email 200890949@qq.com
 */

@SuppressWarnings("ALL")
@Service
@DataBase("lyt_game_db")
@Transactional(value = "transactionManager")
public class PaymentDescSvImpl implements PaymentDescService {

    @Autowired
    private PaymentDescMapper mapper;

    @Override
    public List<PaymentDesc> getList(SearchBase searchBase) {
        PaymentDescExample example = new PaymentDescExample();
        PaymentDescExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(searchBase.getId())){
            criteria.andIdEqualTo(Integer.valueOf(searchBase.getId()));
        }
        example.setOrderByClause("payment_id ASC,id ASC");
        return mapper.selectByExample(example);
    }

    @Override
    public void add(PaymentDesc paymentReq) {
        PaymentDesc paymentDesc = new PaymentDesc();
        paymentDesc.setPaymentDescContent(paymentReq.getPaymentDescContent());
        paymentDesc.setPaymentId(paymentReq.getPaymentId());
        try {
            mapper.insert(paymentDesc);
        }catch (Exception e){
            throw new AjaxException("添加失败");
        }
    }

    @Override
    public void update(PaymentDesc paymentReq) {
        PaymentDesc paymentDesc = mapper.selectByPrimaryKey(paymentReq.getId());
        paymentDesc.setPaymentDescContent(paymentReq.getPaymentDescContent());
        paymentDesc.setPaymentId(paymentReq.getPaymentId());
        mapper.updateByPrimaryKeySelective(paymentDesc);
    }

    @Override
    public void delSignIn(List<Integer> list) {
        PaymentDescExample example = new PaymentDescExample();
        PaymentDescExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(list);
        try {
            mapper.deleteByExample(example);
        }catch (Exception e){
            throw new AjaxException("删除失败 请重试");
        }
    }

    @Override
    public boolean checkName(String name, String id) {
        return false;
    }
}
